package com.qyhl.webtv.module_news.luckydraw;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.SectionBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by Administrator on 2018/6/8.
 */

public class LuckDrawModel implements LuckDrawContract.LuckDrawModel {
    private LuckDrawPresenter mPresenter;

    public LuckDrawModel(LuckDrawPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取配置栏目
     *
     * @param catalogId
     */
    @Override
    public void getSections(String catalogId,String typeId) {

        EasyHttp.get(NewsUrl.GET_MENU_LIST)
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("siteId", CommonUtils.getInstance().getSite()+ "")
                .params("menuId", catalogId)
                .params("menuSecType",typeId)
                .params("menuType", "1")
                .execute(new SimpleCallBack<List<SectionBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(2, "暂无任何内容！");
                        } else {
                            mPresenter.setError(1, "解析出错，数据加载失败！");
                        }
                    }

                    @Override
                    public void onSuccess(List<SectionBean> sectionBeans) {
                        if (sectionBeans != null && sectionBeans.size() > 0) {
                            mPresenter.setDatas(sectionBeans);
                        } else {
                            mPresenter.setError(2, "暂无任何内容！");
                        }
                    }
                });
    }

}
